package xyz.ssf.cloud.common.config;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import com.upyun.RestManager;
import lombok.Data;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@Data
@Configuration
@ConfigurationProperties(prefix = "upyun")
public class UpYunConfig {
    
    private static final Logger log = LoggerFactory.getLogger(UpYunConfig.class);
    
    /**
     * 服务名称
     */
    private String bucketName;
    
    /**
     * 操作员名称
     */
    private String operatorName;
    
    /**
     * 操作员密码
     */
    private String operatorPwd;
    
    /**
     * 加速域名
     */
    private String domain;
    
    @Bean
    public RestManager upYunManager() {
        try {
            log.info("正在初始化又拍云管理器...");
            log.info("服务名称: {}", bucketName);
            log.info("操作员名称: {}", operatorName);
            
            // 创建RestManager实例，使用操作员名称和密码
            return new RestManager(bucketName, operatorName, operatorPwd);
        } catch (Exception e) {
            log.error("初始化又拍云管理器失败: {}", e.getMessage());
            throw new RuntimeException("初始化又拍云管理器失败: " + e.getMessage());
        }
    }
    
    public String getDomain() {
        return domain;
    }
} 